<template>
  <div>
    <!-- 索赔结算单查询 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="110" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :is-select-column="false"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary"  :click="claimExportData">导出</multiuse-button>
      </template>
    </FilterTable>
    <Drawer :visible.sync="visible" :title="dialogTitle" width="60%" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <xiangqing @close="close" @save="save" :rowData="rowData"></xiangqing>
    </Drawer>
  </div>
</template>
<script>
import moment from "moment";
import xiangqing from './xiangqing.vue';
import { exportExcelFile } from '@/utils/index';
import { getAppId } from '@/assets/js/auth';
import { dictionary } from '@/utils/dictMixin';
import { getClaimAccountInfo ,getPartType,getClaimListForExport,qurpBatch,exporturl} from '@/api/claim/dealer/ClaimStatementQueryDealer';
// mock 方法
//import mockFun from "@/mock/fun"
//const { mockList } = mockFun.ClaimStatementQueryDealer.mockFunWrap()// 涉及闭包 所以需要先调用外层函数一次 然后通过解构获取对应mock方法

export default {
  mixins: [dictionary],
  components: {
    xiangqing
  },
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: true,
      infoId: null,
      fetchapi: getClaimAccountInfo ,//getClaimAccountInfo,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      rowData: {},
      columns: this.creatHeader(),
      fetchParams: {xhrAbort: false}, //ipa 接口
      selectedRows: [], //选中服务站
      dialogTitle: '结算信息详情',
      visibleAdd: false
    };
  },
  created() {
    this.chuqi();
  },
  methods: {
    //翻译
    async chuqi() {
      // const res = await getPartType({ type: 5548 });
      // delete  res.data[2]
      // if (res.resultCode == 200) {
      //   this.topFilterInit.find(x => x.fieldName == 'batchStatus').initialValue = '';
      //   this.topFilterInit.find(x => x.fieldName == 'batchStatus').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
      // }


      // const res4 = await getPartType( {type:5543});
      // if (res4.resultCode == 200) {
      //
      //   if (getAppId() == 'arcfox') {
      //     delete res4.data[0];
      //   }
      //
      //   this.topFilterInit.find(x => x.fieldName == 'carType').initialValue = '';
      //   this.topFilterInit.find(x => x.fieldName == 'carType').itemList = res4.data.map(y =>({ text: y.codeCnDesc, value: y.codeId }));
      // }
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    close() {
      this.visible = false;
    },
    chooseOrderNo(val) {
      this.rowData = val;
      this.visible = true;
    },
    save() {
      this.visible = false;
      this.fetchParams = { ...this.fetchParams };
    },
    // 导出
   async exportFileBtn() {
      let json = Object.assign({}, { CODE: 'CODE_00000206' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // let beginCreatedAt = this.topFilterInit.find(x => x.fieldName == "invoiceDateStart|invoiceDateEnd").initialValue[0];
      // let endCreatedAt = this.topFilterInit.find(x => x.fieldName == "invoiceDateStart|invoiceDateEnd").initialValue[1];
      // if(!beginCreatedAt) {
      //   this.$notify.warning({ title: '提示信息', message: '开票开始日期不可为空！' });
      //   return
      // }
      // if(!endCreatedAt) {
      //   this.$notify.warning({ title: '提示信息', message: '开票结束日期不可为空！' });
      //   return
      // }
      // if(getAppId() == 'arcfox') {
      //   if (moment(moment(endCreatedAt).format('YYYY-MM-DD')).diff(moment(beginCreatedAt), 'months', true) > 12) {
      //     this.$notify.warning({ title: '提示信息', message: '开票日期跨度不可超过十二个月！' });
      //     return
      //   }
      // } else {
      //   if (moment(moment(endCreatedAt).format('YYYY-MM-DD')).diff(moment(beginCreatedAt), 'months', true) > 12) {
      //     this.$notify.warning({ title: '提示信息', message: '开票日期跨度不可超过十二个月！' });
      //     return
      //   }
      // }
      // let obj = Object.assign({}, this.fetchParams, {xhrAbort: false});
      // obj.invoiceDateStart = this.topFilterInit.find(x => x.fieldName == "invoiceDateStart|invoiceDateEnd").initialValue[0];
      // obj.invoiceDateEnd = this.topFilterInit.find(x => x.fieldName == "invoiceDateStart|invoiceDateEnd").initialValue[1];
      // getListForExport(obj).then(res => {
      //   exportExcelFile(res.data, '索赔结算单信息');
      // });
    },
    add() {
      this.visibleAdd = true;
    },
    closeAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val,{xhrAbort: false});
      console.log(val);
    },
    // 索赔结算单导出
    async claimExportData() {
      await getClaimListForExport(this.fetchParams).then(res => {
        console.log(res);
        exportExcelFile(res.data, '索赔结算单导出');
      });
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '结算单号', fieldName: 'settleNo', placeholder: '请输入结算单号...', initialValue: '' },
        { type: 'INPUT', label: '结算月份', fieldName: 'settleDate', placeholder: '请输入结算月份...', initialValue: '' },
        { type: 'SELECT', label: '结算单状态', fieldName: 'settleStatus', placeholder: '请选择结算单状态...', initialValue: '', itemList: this.createDictList('5001')},
        {
          type: 'RANGE_DATE',
          label: '下发时间',
          fieldName: 'beginIssueDate|endIssueDate',
          placeholder: '请输入',
          dateType: 'datetimerange',
          initialValue: [
            moment(new Date())
              .subtract(6, 'month')
              .format('YYYY-MM-DD 00:00:00'),
            moment(new Date()).format('YYYY-MM-DD 23:59:59')
          ],
          rules: [{ required: false, message: '请选择日期', trigger: 'change' }] //方便搜索查数据，记得放开
        },
        { type: 'SELECT', label: '索赔车辆属性', fieldName: 'carType', placeholder: '请选择索赔车辆属性...', initialValue: '',itemList: this.createDictList('5543') }
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          fixed: 'left',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.chooseOrderNo(props.row)}>
                  查看
                </multiuse-button>
              </div>
            );
          }
        },
        { title: '结算单状态', dataIndex: 'settleStatus', sorter: true, showOverflowTooltip: true, dictItems: this.createDictList('5001')},
        { title: '结算单号', dataIndex: 'settleNo', sorter: true },
        { title: '结算月份', dataIndex: 'settleDate', sorter: true },
        { title: '结算单类型', dataIndex: 'finalStatementType', dictItems: this.createDictList('5002')},
        // { title: '结算单类型', dataIndex: 'finalStatementType', sorter: true },
        { title: '服务站代码', dataIndex: 'dealerCode', sorter: true },
        { title: '服务站简称', dataIndex: 'dealerName', sorter: true },
        { title: '索赔单数', dataIndex: 'claimSum', sorter: true },
        { title: '结算金额', dataIndex: 'settleAmount', sorter: true },
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
